package com.bblocks.common.anti_reptile.interceptor;

import com.bblocks.common.anti_reptile.config.bean.RuleComm;
import com.bblocks.common.anti_reptile.constant.AntiReptileConsts;
import com.bblocks.common.anti_reptile.module.VerifyImageDTO;
import com.bblocks.common.anti_reptile.util.CrosUtil;
import lombok.NonNull;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>Project: bb-anti-reptile - ResultStrategyDefault</p>
 * <p>描述：结果默认方案-json错误码返回</p>
 *
 * @Author Zhao [125043150@qq.com]
 * @Date 2024/3/27 9:13
 * @Version 1.0
 * @since 8
 */
public class ResultStrategyDefault implements ResultStrategy {

    @Override
    public void process(@NonNull RuleComm matchRule, HttpServletRequest request, HttpServletResponse response) throws IOException {
        String lockResponse = matchRule.getLockResponse();
        if(lockResponse == null || lockResponse.length() == 0){
            lockResponse = AntiReptileConsts.JSON_RET;
        }
        CrosUtil.setCrosHeader(response);
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(lockResponse);
        response.getWriter().close();
    }
}
